<template>
  <div>
    <template>
      <el-table :data="list" border style="width: 100%">
        <el-table-column prop="id" label="规格编号" width="180">
        </el-table-column>
        <el-table-column prop="specsname" label="规格名称" width="180">
        </el-table-column>
        <el-table-column label="规格属性">
          <template slot-scope="scope">
            <el-tag type="success" v-for="item in scope.row.attrs" :key="item">
              {{ item }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="状态">
          <template slot-scope="scope">
            <el-button type="primary" v-if="(scope.row.status = 1)"
              >启用</el-button
            >
            <el-button type="info" v-else>禁用</el-button>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="primary" @click="willEdit(scope.row.id)"
              >修改</el-button
            >
            <el-button type="danger" @click="del(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </div>
</template>
</div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { reqspecsdelete } from "../../../http/api";
import { successAlert } from "../../../utils/alert";
export default {
  props: [],
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      list: "specs/list",
    }),
  },
  mounted() {
    this.reqList();
  },
  methods: {
    ...mapActions({
      reqList: "specs/reqList",
    }),
    willEdit(id) {
      this.$emit("willEdit", id);
    },
    del(id) {
      reqspecsdelete({ id: id }).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          this.reqList();
        }
      });
    },
  },
};
</script>
<style scoped lang="less">
@import "../../../less/index.less";
</style>